package org.zju.demo.shoppingdemo.controller;
import com.google.gson.Gson;
import org.zju.demo.shoppingdemo.activity.BaseActivityInterface;
import org.zju.demo.shoppingdemo.model.Request.LoginModel;
import org.zju.demo.shoppingdemo.model.Request.RegisterModel;
import org.zju.demo.shoppingdemo.model.Request.UpdateUserModel;
import org.zju.demo.shoppingdemo.model.Request.GetUserinfoModel;
import org.zju.demo.shoppingdemo.model.response.BaseResponse;
import org.zju.demo.shoppingdemo.model.response.UserinfoResponse;
import org.zju.demo.shoppingdemo.task.HttpAsyncTask;
import org.zju.demo.shoppingdemo.utils.Constant;

/**
 * Created by ZJDX on 2015/9/9.
 */
public class UserInfoController {

    private UserInfoController(){
    }

    public static void doLogin(BaseActivityInterface activityInterface, LoginModel model) {
        // prepare params for HttpAsyncTask
        // url, method, jsonString
        Gson gson = new Gson();
        Object[] params = {Constant.LOGIN_URL, Constant.POST_METHOD, gson.toJson(model)};
        HttpAsyncTask task = new HttpAsyncTask(activityInterface, BaseResponse.class);
        task.execute(params);
    }

    public static void doRegister(BaseActivityInterface activityInterface, RegisterModel model) {
        Gson gson = new Gson();
        Object[] params = {Constant.REGISTER_URL, Constant.POST_METHOD, gson.toJson(model)};
        HttpAsyncTask task = new HttpAsyncTask(activityInterface, BaseResponse.class);
        task.execute(params);
    }

    public static void doModify(BaseActivityInterface activityInterface, UpdateUserModel model) {
        Gson gson = new Gson();
        Object[] params = {Constant.UPDATEUSER_URL, Constant.POST_METHOD, gson.toJson(model)};
        HttpAsyncTask task = new HttpAsyncTask(activityInterface, BaseResponse.class);
        task.execute(params);
    }
    public static void doGetUserInfo(BaseActivityInterface activityInterface, GetUserinfoModel model) {
        Gson gson = new Gson();
        Object[] params = {Constant.GETUSERINFO_URL, Constant.POST_METHOD, gson.toJson(model)};
        HttpAsyncTask task = new HttpAsyncTask(activityInterface, UserinfoResponse.class);
        task.execute(params);
    }
}
